package top.kaoshanji.p1ch09d;

/**
 * 代码清单-p1ch09d-213页a：构造器和多态，不会生成你所期望的结果
 * author kaoshanji
 * ^_^
 * create time 2025/3/9 18:58
 */
public class PolyConstructors {

    public static void main(String[] args) {
        new RoundGlyph(5);
    }


}

class Glyph {
    void draw() { System.out.println("Glyph.draw()"); }
    Glyph() {
        System.out.println("Glyph() before draw()");

        // 这是一个普通的方法，会被子类重写
        draw();

        System.out.println("Glyph() after draw()");
    }
}

class RoundGlyph extends Glyph {

    private int radius = 1;

    RoundGlyph(int r) {
        radius = r;
        System.out.println("RoundGlyph.RoundGlyph(), radius = " + radius);
    }

    // 该方法在基类的构造器中被调用了
    @Override
    void draw() {
        System.out.println("RoundGlyph.draw(), radius = " + radius);
    }
}
